home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / utils / sound / players / unix / rplay / rplay.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-20  |  2.4 KB  |  130 lines

  1. /*
  2.  * rplay.c
  3.  *
  4.  * Copyright (c) 1992 by Mark Boyns
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted, provided
  8.  * that the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation.  This software is provided "as is" without express or
  11.  * implied warranty.
  12.  */
  13.  
  14. #include <stdio.h>
  15. #include <strings.h>
  16. #include "version.h"
  17. #include "rplay.h"
  18.  
  19. char    *usage = "usage: rplay host[:host...] [option] sound ...\n\
  20.     Where option can be only one of the following:\n\
  21.     -s    stop\n\
  22.     -p    pause\n\
  23.     -c    continue\n\
  24.     -v n    play at volume n (0 <= n <= 255)\n\
  25.     or no option which will play at the default volume (128)\n\
  26. ";
  27.  
  28. main(argc, argv)
  29. int    argc;
  30. char    **argv;
  31. {
  32.     int        rplay_fd, c, attr, append_attr, volume, val; 
  33.     char        *hosts, *p, *q;
  34.     RPLAY        *rp;  
  35.     extern char    *optarg; 
  36.     extern int    optind;
  37.  
  38.     if (argc < 3) {
  39.         fprintf(stderr, usage);
  40.         exit(1);
  41.     }
  42.  
  43.     hosts = argv[1];
  44.  
  45.     argc--;
  46.     argv++; 
  47.  
  48.     attr = RPLAY_VOLUME_PLAY;
  49.     append_attr = RPLAY_APPEND_VOLUME_PLAY;
  50.     volume = RPLAY_DEFAULT_VOLUME;
  51.  
  52.     while((c = getopt(argc, argv, "v:spch")) != -1) {
  53.         switch(c) {
  54.         case 'v':
  55.             volume = atoi(optarg);
  56.             break;
  57.  
  58.         case 's':   
  59.             attr = RPLAY_STOP;
  60.             append_attr = RPLAY_APPEND_STOP;
  61.             break;
  62.  
  63.         case 'p': 
  64.             attr = RPLAY_PAUSE;
  65.             append_attr = RPLAY_APPEND_PAUSE;
  66.             break;
  67.  
  68.         case 'c':  
  69.             attr = RPLAY_CONTINUE;
  70.             append_attr = RPLAY_APPEND_CONTINUE;
  71.             break;
  72.         
  73.         case 'h':
  74.         case '?':
  75.             fprintf(stderr, usage);
  76.             exit(1);
  77.         } 
  78.     }
  79.              
  80.     if (optind == argc) {
  81.         fprintf(stderr, usage);
  82.         exit(1);
  83.     } 
  84.     
  85.     rp = rplay_create();  
  86.     if (rp == NULL) {
  87.         rplay_perror("rplay_create");
  88.         exit(1);
  89.     }
  90.       
  91.     val = rplay_set(rp, attr,
  92.         argv[optind++], attr == RPLAY_VOLUME_PLAY ? volume : NULL,
  93.         NULL);
  94.     if (val < 0) {
  95.         rplay_perror("rplay_set");
  96.         exit(1);
  97.     }
  98.  
  99.     while(argv[optind] != NULL) {
  100.         val = rplay_set(rp, append_attr,
  101.             argv[optind++], append_attr == RPLAY_APPEND_VOLUME_PLAY ? volume : NULL,
  102.             NULL);
  103.         if (val < 0) {
  104.             rplay_perror("rplay_set");
  105.             exit(1);
  106.         }
  107.     }
  108.  
  109.     q = hosts;
  110.     do {
  111.         p = q;
  112.         q = index(p, ':');
  113.         if (q != NULL) {
  114.             *q++ = '\0';
  115.         }
  116.         rplay_fd = rplay_open(p);
  117.         if (rplay_fd < 0) {
  118.             rplay_perror(p);
  119.             exit(1);
  120.         }
  121.         if (rplay(rplay_fd, rp) < 0) {
  122.             rplay_perror(p);
  123.             exit(1);
  124.         }
  125.         rplay_close(rplay_fd);
  126.     } while(q != NULL);
  127.  
  128.     exit(0);
  129. }
  130.